#ifndef __CLIENT_REQUEST_GET_included
#define __CLIENT_REQUEST_GET_included

#include <map>
#include "ClientRequest.h"
#include "../client-common/Device.h"
#include "../engine/DebugStream.h"

using namespace Client::Common;

class CRequestGet : public CClientRequest {

	static map<string, CRequestAction*> mActions;

	/*
	void GetFileList() {
	
		int oldver = GetParameterInt(string("oldver"));
		string& devices = GetParameter(string("devices"));

		TableRef tf;
		
		if(devices == "all") tf = CSyncFile::Query();
		else tf = CSyncFile::QueryAfter(oldver);

		if(!tf || tf->GetCount() == 0) {
			Response(RESPONSE_STATUS_OK);
			if(tf) tf->Close();
			return;
		}

		TableRef ts = CSyncFile::GetSerializedTable(*tf);
		tf->Close();

		string js = ts->ToString();
		ts->Close();
		
		ResponseRef response = InitResponse();
		response->SetStatus(RESPONSE_STATUS_OK);
		response->SetContent(js, string(PACKAGE_CONTENT_TYPE_JSON));
		mConnection->SendResponse(response);

	}

	void GetFile() {
		
		string& id = GetParameter(string("id"));
		if(id.length() == 0) {
			Response(RESPONSE_STATUS_BadRequest);
			return;
		}

		SyncFileRef sf = CSyncFile::QueryById(id);
		if(!sf || sf->mStatus != FILE_STATUS_NORMAL || sf->mType != FILE_TYPE_FILE) {
			Response(RESPONSE_STATUS_FileNotFound);
			return;
		}

		string file_path;
		Util::CConverter::UTF8_TO_Ascii(sf->mStorePath, file_path);

		boost::filesystem::path file = file_path;
		if(!boost::filesystem::exists(file) || !boost::filesystem::is_regular_file(file)) {
			Response(RESPONSE_STATUS_FileNotFound);
			return;
		}
		
		ResponseRef response = InitResponse();
		response->SetStatus(RESPONSE_STATUS_OK);
		response->SetContentFile(file_path, string(PACKAGE_CONTENT_TYPE_RAW));

		mConnection->SendResponse(response);

		sf->mSyncCount++;
		CSyncFile::UpdateSyncFile(sf);
	}

	void GetDevices() {
		
		TableRef td = Client::Common::CDevice::Query();
		if(!td || td->GetCount() == 0) {
			Response(RESPONSE_STATUS_OK);
			if(td) td->Close();
			return;
		}

		TableRef ts = Client::Common::CDevice::GetSerializedTable(*td);
		td->Close();

		string js = ts->ToString();
		ts->Close();
		
		ResponseRef response = InitResponse();
		response->SetStatus(RESPONSE_STATUS_OK);
		response->SetContent(js, string(PACKAGE_CONTENT_TYPE_JSON));
		mConnection->SendResponse(response);
	}
	*/
public :

	CRequestGet() :
		CClientRequest(string(COMMAND_GET))
	{
	}

	CRequestGet(boost::shared_ptr<std::istream> is) :
		CClientRequest(string(COMMAND_GET), is)
	{
	}

	virtual void DoRequest();

	static void RegisterAction(string& target, CRequestAction* action) {
		mActions[target] = action;
	}
};

#endif //__CLIENT_REQUEST_GET_included